package com.study.operateDB;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.study.operateDB.Enum.Config;


public class ConnectionFactory {

	private ConnectionFactory() {
	}

	public static Connection openConnection(Config config) {
		Connection conn = null;
		try {
			Class.forName(config.driverClass());
			conn = DriverManager.getConnection(config.uRLString(),
					config.getValue(Config.USER), config.getValue(Config.PASSWORD));
		} catch (SQLException ex) {
			Logger.getLogger(ConnectionFactory.class.getName()).error(
					ex.getMessage(), ex);
		} catch (ClassNotFoundException ex) {
			Logger.getLogger(ConnectionFactory.class.getName()).error(
					ex.getMessage(), ex);
		}

		return conn;
	}

	public static void closeConnection(Connection connection) {
		try {
			if (connection != null) {
				connection.close();
			}
		} catch (SQLException ex) {
			Logger.getLogger(ConnectionFactory.class.getName()).error(
					ex.getMessage(), ex);
		}
	}

}
